package com.cn.aam.checaiduo.ui.me.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.baoyz.widget.PullRefreshLayout;
import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.base.BaseFragment;
import com.cn.aam.checaiduo.base.adapter.delegator.RecyclerViewDelegatorV2;
import com.cn.aam.checaiduo.bean.me.RechageB;
import com.cn.aam.checaiduo.bean.me.WithDrawB;
import com.cn.aam.checaiduo.ui.me.adapter.RechargeRecordAdapter;
import com.cn.aam.checaiduo.ui.me.adapter.WithdrawRecordAdapter;
import com.cn.aam.checaiduo.ui.me.command.RecharCommand;
import com.cn.aam.checaiduo.ui.me.command.WithDrawCommand;
import com.cn.aam.checaiduo.widget.MultiStateView;

import butterknife.BindView;


/**
 * 充值和提现的记录
 */
public class RechargeWithDrawRecordFragment extends BaseFragment {

    public static final int RECHAR = 1;//充值记录
    public static final int WITHDRAW = 2;//提现记录

    private RecharCommand recharCommand;
    private WithDrawCommand drawCommand;

    private RecyclerViewDelegatorV2<RechageB> recharDelegator;
    private RecyclerViewDelegatorV2<WithDrawB> drawDelegator;

    @BindView(R.id.id_recyclerview)
    RecyclerView mRecycler;
    @BindView(R.id.id_swipe)
    PullRefreshLayout mSwipe;
    @BindView(R.id.id_multistateview)
    MultiStateView idMultistateview;


    public static RechargeWithDrawRecordFragment newInstance(int flag) {
        RechargeWithDrawRecordFragment intance = new RechargeWithDrawRecordFragment();
        Bundle b = new Bundle();
        b.putInt("flag", flag);
        intance.setArguments(b);
        return intance;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.content_universal_normal_recyclerview;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        int flag = getArguments().getInt("flag");
        idMultistateview.setViewForState(R.layout.content_list_state_empty1, MultiStateView.VIEW_STATE_EMPTY);
        if (flag == RECHAR) {
            getRechar();
        } else {
            getWithdraw();
        }

    }

    private void getWithdraw() {
        drawCommand = new WithDrawCommand();
        WithdrawRecordAdapter adapter = new WithdrawRecordAdapter(mActivity);
        drawDelegator = new RecyclerViewDelegatorV2<>(mActivity, idMultistateview, mSwipe, mRecycler, adapter, drawCommand);
        drawDelegator.beginHeaderRefreshing();
    }

    private void getRechar() {
        recharCommand = new RecharCommand();
        RechargeRecordAdapter adapter = new RechargeRecordAdapter(mActivity);
        recharDelegator = new RecyclerViewDelegatorV2<>(mActivity, idMultistateview, mSwipe, mRecycler, adapter, recharCommand);
        recharDelegator.beginHeaderRefreshing();
    }
}
